import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'const.dart';

class ToastController extends GetxController {

  //警告框
  void showCenterToast(String message) {
    Get.dialog(
      AlertDialog(
        backgroundColor: Colors.black,
        contentPadding: EdgeInsets.symmetric(vertical: 20, horizontal: 30),
        content: Text(
          message,
          textAlign: TextAlign.center,
          style: TextStyle(
            color: Colors.white,
            fontSize: 16,
            fontWeight: FontWeight.w500,
          ),
        ),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
      ),
      barrierDismissible: false,
    );
    // 0.6秒后自动关闭
    Future.delayed(Duration(milliseconds: 600), () {
      if (Get.isDialogOpen!) Get.back();
    });
  }

  //查看设备详情
  void showInfo(Map<String, dynamic> data) {
    Get.dialog(
      AlertDialog(
        backgroundColor: Colors.white,
        title: Center(
          child: Text('设备详情', style: TextStyle(fontWeight: FontWeight.bold)),
        ),
        content: Container(
          constraints: BoxConstraints(maxHeight: 350),
          padding: EdgeInsets.all(10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text('MAC地址：${data['addr']}', style: TextStyle(fontSize: 16)),
              Text('信号强度：${data['rssi']}dbm', style: TextStyle(fontSize: 16)),
              Text('组号：${data['group_id']}', style: TextStyle(fontSize: 16)),
              Text(
                '设备类型：${deviceType[data['device_type']]}',
                style: TextStyle(fontSize: 16),
              ),
              Text(
                '亮灯模式：${data['mode'] == 0 ? '手动模式' : '自动模式'}',
                style: TextStyle(fontSize: 16),
              ),
              if (data['mode'] == 0) ...[
                Text(
                  '亮灯延迟时间：${data['lightDelayTime']}s',
                  style: TextStyle(fontSize: 16),
                ),
                Text(
                  '无人亮度：${data['unmannedBrightness']}%',
                  style: TextStyle(fontSize: 16),
                ),
                Text(
                  '有人亮度：${data['peopleBrightness']}%',
                  style: TextStyle(fontSize: 16),
                ),
                Text(
                  '灭灯延迟时间：${data['dark_delay']}s',
                  style: TextStyle(fontSize: 16),
                ),
              ] else ...[
                Text(
                  '固定亮度：${data['fixedBrightness']}%',
                  style: TextStyle(fontSize: 16),
                ),
              ],
              Text(
                '是否转发：${data['forwarding'] == 0 ? '转发' : '不转发'}',
                style: TextStyle(fontSize: 16),
              ),
              Text('次数：${data['ttl_count']}', style: TextStyle(fontSize: 16)),
              Text(
                '是否联网：${data['network'] == 0 ? '支持联网' : '不支持联网'}',
                style: TextStyle(fontSize: 16),
              ),
              Text('功率：${data['tx_power']}dbm', style: TextStyle(fontSize: 16)),
            ],
          ),
        ),
      ),
    );
  }

}
